package com.ad.pet.app.account.adapter;

import android.app.Activity;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.common.data.utils.date.DateUtil;
import com.ad.pet.models.remote.account.order.BigOrder;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * 到店预约订单列表
 * Created by liuyixiang on 2019/11/20.
 */

public class IndoorOrderAdapter extends BaseQuickAdapter<BigOrder, BaseViewHolder> {
    private OnItemClickLinstener mOnItemClickLinstener;

    public IndoorOrderAdapter(@Nullable List<BigOrder> data) {
        super(R.layout.item_indoor_order_layout, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, BigOrder item) {
        TextView tv_title = helper.getView(R.id.tv_order_number);
        TextView tv_create = helper.getView(R.id.tv_time);
        RecyclerView recycler_good = helper.getView(R.id.recycler_good);
        TextView tv_left = helper.getView(R.id.tv_left);
        TextView tv_status = helper.getView(R.id.tv_status);
        TextView tv_right = helper.getView(R.id.tv_right);
        TextView tvCount = helper.getView(R.id.tv_count);
        tvCount.setText("合计:￥"+item.getOrder_money());
        tv_create.setText(DateUtil.stampToDate(Long.valueOf(item.getCreate_time()) * 1000, "yyyy-MM-dd hh:mm"));
        if ("0".equals(item.getOrder_status())) {
            helper.getView(R.id.relativeLayout_reduce).setVisibility(View.VISIBLE);
        } else {
            helper.getView(R.id.relativeLayout_reduce).setVisibility(View.GONE);
        }
        tv_right.setText("付款");
        switch (item.getOrder_status()) {
            case "0":
                tv_status.setText("待付款");
                tv_status.setBackgroundResource(R.drawable.shap_waiting_pay_layout);
                break;
            case "4":
                tv_status.setText("已完成");
                tv_status.setBackgroundResource(R.drawable.shap_compelete_status_bg);
                break;
            case "5":
                tv_status.setText("已关闭");
                tv_status.setBackgroundResource(R.drawable.shap_complete_pay_layout);
                break;
        }

        tv_title.setText("单号：" + item.getOrder_no());
        OrderGoodAdapter orderGoodAdapter = new OrderGoodAdapter(item.getOrder_offservice_list());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        recycler_good.setLayoutManager(linearLayoutManager);
        recycler_good.setAdapter(orderGoodAdapter);
        tv_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLinstener.onCancel(helper.getLayoutPosition());
            }
        });

        tv_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLinstener.onConfirm(helper.getLayoutPosition());
            }
        });
        orderGoodAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Navigation.goServiceOrderDetail((Activity) mContext, mData.get(helper.getLayoutPosition()).getOrder_id());
            }
        });


//        helper.getView(R.id.linear).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Navigation.goServiceOrderDetail((Activity) mContext,mData.get(helper.getLayoutPosition()).getOrder_id());
//            }
//        });

    }

    public interface OnItemClickLinstener {
        void onConfirm(int position);

        void onCancel(int position);
    }

    public void setOn0ItemClickLinstener(OnItemClickLinstener onItemClickLinstener) {
        mOnItemClickLinstener = onItemClickLinstener;
    }
}
